package test.gps;

import android.os.Bundle;
import android.os.Handler;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import android.util.Log;
import android.view.Menu;
import android.view.MotionEvent;
import android.view.Window;
import android.view.WindowManager;
import android.widget.RelativeLayout;
import android.widget.Toast;

public class LogoActivity extends Activity {
	String kind = "first";
	private RelativeLayout logoRelativeLayout;
	private SharedPreferences sp;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);

		sp = this.getSharedPreferences("flag", Context.MODE_WORLD_READABLE);

		String flag = sp.getString("TIMES", "");

		if (flag.equals("no")) {
			kind = "login";
		}
		Editor editor = sp.edit();
		editor.putString("TIMES", "no");
		editor.commit();
		Intent intent1 = getIntent();
		if (intent1.getStringExtra("kind") != null) {
			kind = intent1.getStringExtra("kind");
		}
		// 去除标题
		this.requestWindowFeature(Window.FEATURE_NO_TITLE);
		this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
				WindowManager.LayoutParams.FLAG_FULLSCREEN);
		setContentView(R.layout.guide);
		logoRelativeLayout = (RelativeLayout) findViewById(R.id.logo);
		if (kind.equals("help") || kind.equals("first")) {
			logoRelativeLayout.setBackgroundDrawable(getResources()
					.getDrawable(R.drawable.guide));
		} else {
			logoRelativeLayout.setBackgroundDrawable(getResources()
					.getDrawable(R.drawable.logo));
		}
		if (kind.equals("login") || kind.equals("first")) {
			new Handler().postDelayed(new Runnable() {
				public void run() {

					Intent intent = new Intent(LogoActivity.this,
							MainActivity.class);
					startActivity(intent);
					finish();
				}
			}, 3000);
		}

	}

	@Override
	public boolean dispatchTouchEvent(MotionEvent event) {
		if (kind.equals("help")) {
			finish();
		} else if (kind.equals("first")) {
			Intent intent = new Intent(LogoActivity.this, MainActivity.class);
			startActivity(intent);
			finish();
		}

		return super.dispatchTouchEvent(event);
	}

}
